import dayjs from 'dayjs'

export const createDay = () => {
  let day = []
  for(let i = 1; i <= 24; i++){
    let s = i
    if(i < 10){
      s = `0${i}:00`
    }else{
      s = `${i}:00`
    }
    day.push(s)
  }
  return day.slice(0, dayjs().hour())
}

export const createWeek = () => {
  let week = []
  for(let i = 7; i > 0; i--){
    week.push(dayjs().subtract(i, 'day').format('MM-DD'))
  }
  return week
}

export const createMonth = () => {
  let month = []
  for(let i = 30; i > 0; i--){
    month.push(dayjs().subtract(i, 'day').format('MM-DD'))
  }
  return month
}

export const createYear = () => {
  let year = []
  for(let i = 12; i > 0; i--){
    year.push(dayjs().subtract(i, 'month').format('YYYY-MM'))
  }
  return year
}

// 数组随机取值
export const randomArr = (arr) => {
  let index = Math.floor((Math.random() * arr.length))
  return {
    index,
    value: arr[index]
  }
}
